package Week1.J0416;

import java.util.Scanner;

public class MinCountClimbStairs {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int[] cost = new int[n+1];
        for (int i = 0; i < n; i++) {
            cost[i] = scanner.nextInt();
        }

        int count = 0;

        int i = 0;
        if (cost[0] > cost[1] || cost[1] < cost[2]) {
            i = 1;
        }

        for (int j = i; j < n-1; j++) {
            count += cost[j];
            if (cost[j+1] >= cost[j+2]) {
                j++;
            }
        }

        if (cost[n-1] < cost[n-2]) { // [9] < [8]
            count += cost[n-1];
        }

        System.out.println(count);
    }
}
